package com.lucas.servlet.chapter3_3.mapper;

import com.lucas.servlet.chapter3_3.entity.Student;
import org.apache.ibatis.annotations.*;

@Mapper
public interface StudentMapper {
    @Results(id = "studentmap", value = {
            @Result(property = "student_name", column = "student_name"),
            @Result(property = "class_name", column = "class_name"),
            @Result(property = "sex", column = "sex")

    })

    @Select("select * from student where student_name = #{student_name}")
    Student getStudentByName(@Param("student_name") String student_name, String class_name);

    //新增，占位符会自动和方法里的参数进行映射，如果参数是实体类，那么要求实体类对象参数名字和占位符对应
    @Insert("insert into student(student_name, class_name, sex) values (#{student_name}, #{class_name}, #{sex})")
    int createStudent(Student student);

    @Update("update student set student_name = #{student_name}, class_name = #{class_name}, sex = #{sex} where id = #{id}")
    int updateStudent(Student student);

    // 根据用户名删除用户的方法
    @Delete("delete from student where student_name = #{student_name}")
    int deleteStudentByStudentname(@Param("student_name") String student_name);
}
